package com.yiji.fintech.musfinance.common.utils;

import com.acooly.core.utils.enums.ResultStatus;
import com.yiji.fintech.musfinance.base.enums.TransStatusEnum;
import com.yiji.fintech.musfinance.base.facade.GatewayResultFacade;
import com.yiji.fintech.musfinance.center.base.result.ResultFacade;
import com.yiji.fintech.musfinance.common.domain.base.BaseDomain;

/**
 * 交易结果转status
 * Created by ouwen@yiji.com} on 2017/9/28.
 */
public class TransStatusConverter {
    public static void converter(TransStatusEnum transStatus, ResultFacade result){
        if(transStatus == TransStatusEnum.BANK_SUCCESS){
            result.setStatus(ResultStatus.success);
            result.setCode(ResultStatus.success.getCode());
            result.setDetail(ResultStatus.success.getMessage());
        }else if(transStatus == TransStatusEnum.BANK_FAIL){
            result.setStatus(ResultStatus.failure);
            result.setCode(ResultStatus.failure.getCode());
            result.setDetail(ResultStatus.failure.getMessage());
        }else{
            result.setStatus(ResultStatus.processing);
            result.setCode(ResultStatus.processing.getCode());
            result.setDetail(ResultStatus.processing.getMessage());
        }
    }
    public static void converter(BaseDomain domain, GatewayResultFacade resultFacade){
        if(resultFacade.getStatus() == ResultStatus.success){
            domain.setTransStatus(TransStatusEnum.BANK_SUCCESS);
            domain.setStatus(ResultStatus.success);
        }else if(resultFacade.getStatus() == ResultStatus.failure){
            domain.setTransStatus(TransStatusEnum.BANK_FAIL);
            domain.setStatus(ResultStatus.failure);
        }else {
            domain.setTransStatus(TransStatusEnum.BANK_PROCESSING);
            domain.setStatus(ResultStatus.processing);
        }
    }
}
